package com.zb.emq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * 项目启动自定触发，初始化方法
 */
@Component
@Slf4j
public class Monitor {

    @Autowired
    private EmqClient emqClient;

    @PostConstruct
    public void init() {
        log.info("项目初始化！");
        try {
            emqClient.connect();
            emqClient.subscribe("mytopic");
            log.info("主题订阅成功！");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
